package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.constant.MessageConstant;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.QiNiuUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: health_parent
 * @description: 用户使用网页端，所有套餐页
 * @author: HuChunping
 * @create: 2021-01-15 17:22
 **/
@RestController
@RequestMapping("/setmeal")
public class SetmealMobileController {

    @Reference
    private SetmealService setmealService;

    /**
    * @Description: 查询所有套餐，用于用户端套餐展示
    * @Param: []
    * @return: com.itheima.health.entity.Result
    * @Author: HuChunping
    * @Date: 2021/1/15-17:38
    */
    @GetMapping("/getSetmeal")
    public Result getSetmeal(){
        List<Setmeal> setmeals = setmealService.findAll();
        // lambda表达式，foreach遍历所有图片，然后设置图片名，由于图片名是setmeals的属性，所以这个setmeals的图片名也变了
        setmeals.forEach(s->s.setImg(QiNiuUtils.DOMAIN+s.getImg()));
        return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS, setmeals);
    }

    /**
    * @Description: 套餐详情页查询套餐详情
    * @Param: []
    * @return: com.itheima.health.entity.Result
    * @Author: HuChunping
    * @Date: 2021/1/15-19:59
    */
    @GetMapping("/findDetailById")
    public Result findDetailById(int id){
        Setmeal setmeal = setmealService.findDetailById(id);
        setmeal.setImg(QiNiuUtils.DOMAIN+setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }

    /**
    * @Description: 套餐预约页面，通过id查询套餐
    * @Param: [id]
    * @return: com.itheima.health.entity.Result
    * @Author: HuChunping
    * @Date: 2021/1/15-23:06
    */
    @GetMapping("/findById")
    public Result findById(int id){
        Setmeal setmeal = setmealService.findById(id);
        setmeal.setImg(QiNiuUtils.DOMAIN + setmeal.getImg());
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
    }
}
